﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:APP_PROFILESINFO
	/// </summary>
	public partial class APP_PROFILESINFO : BaseDAL<GSLMS.Entity.TB_APP_PROFILESINFO>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public APP_PROFILESINFO()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_APP_PROFILESINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_ANNEXTYPE", model.ANNEXTYPE),
								new OracleParameter("P_SAVEURL", model.SAVEURL),
								new OracleParameter("P_FILENAME", model.FILENAME),
								new OracleParameter("P_FILEFLAG", model.FILEFLAG),
								new OracleParameter("P_PID", model.PID)};
  
			for (int i = 0; i < 7; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
                int num = OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_profileinfo_add", parms);
                if (num == 1)
                    flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据,不再使用
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_APP_PROFILESINFO model)
		{
			bool flag = false;
            //OracleParameter[] parms =new OracleParameter[]{
            //                    new OracleParameter("P_ID", model.ID),
            //                    new OracleParameter("P_PROID", model.PROID),
            //                    new OracleParameter("P_ANNEXTYPE", model.ANNEXTYPE),
            //                    new OracleParameter("P_SAVEURL", model.SAVEURL),
            //                    new OracleParameter("P_FILENAME", model.FILENAME),
            //                    new OracleParameter("P_FILEFLAG", model.FILEFLAG),
            //                    new OracleParameter("P_PID", model.PID)};
  
            //for (int i = 0; i < 7; i++)
            //{
            //    parms[i].Direction = ParameterDirection.Input;
            //}

            //try
            //{
            //    OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_app_profilesinfo_update", parms);
            //    flag = true;
            //}
            //catch (Exception ex)
            //{
            //    log.ExceptionHand(ex);
            //}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
               int num=OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_profileinfo_delete", parms);
               if (num == 1)
                   flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_APP_PROFILESINFO DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_APP_PROFILESINFO model = new GSLMS.Entity.TB_APP_PROFILESINFO();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["ANNEXTYPE"]!=null && dr["ANNEXTYPE"].ToString()!="")
				{
					model.ANNEXTYPE=dr["ANNEXTYPE"].ToString();
				}
				if(dr["SAVEURL"]!=null && dr["SAVEURL"].ToString()!="")
				{
					model.SAVEURL=dr["SAVEURL"].ToString();
				}
				if(dr["FILENAME"]!=null && dr["FILENAME"].ToString()!="")
				{
					model.FILENAME=dr["FILENAME"].ToString();
				}
				if(dr["FILEFLAG"]!=null && dr["FILEFLAG"].ToString()!="")
				{
                    model.FILEFLAG = OracleHelper.ToInt(dr["FILEFLAG"].ToString());
				}
				if(dr["PID"]!=null && dr["PID"].ToString()!="")
				{
					model.PID=OracleHelper.ToLong(dr["PID"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_APP_PROFILESINFO GetByID(long ID)
		{
			GSLMS.Entity.TB_APP_PROFILESINFO sModel = new GSLMS.Entity.TB_APP_PROFILESINFO();
			string sql = "";
			sql = "select * from TB_APP_PROFILESINFO where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_APP_PROFILESINFO> GetList(GSLMS.Entity.TB_APP_PROFILESINFO searchParam)
		{
			var list=new List<GSLMS.Entity.TB_APP_PROFILESINFO>();
			DataTable dt = null;
			string tblName = "TB_APP_PROFILESINFO";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_APP_PROFILESINFO model = new GSLMS.Entity.TB_APP_PROFILESINFO();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			
			return list;
		}

         /// <summary>
         /// 通过立项申请记录ID，提取该立项立项申请的所有附件信息
         /// </summary>
         /// <param name="proInfoID">立项申请记录ID</param>
         /// <param name="fileType">附件类别
         ///10立项申请
         ///20风控分配
         ///30风控审批
         ///40贷款审议
         ///50贷款合同,当传入-1时，则显示所有，不管类别
         ///</param>
         /// <returns></returns>
        public List<GSLMS.Entity.TB_APP_PROFILESINFO> GetAllByProInfoID(long proInfoID,int fileType)
        {
            var list = new List<GSLMS.Entity.TB_APP_PROFILESINFO>();
            string sql = "";
            DataTable dt = null;

            sql = "select * from TB_APP_PROFILESINFO where ProID=" + proInfoID.ToString();
            if (fileType != -1)
                sql += " and FILEFLAG=" + fileType.ToString();


            DataSet ds = OracleHelper.ExecuteDataset(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }

            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    GSLMS.Entity.TB_APP_PROFILESINFO model = new GSLMS.Entity.TB_APP_PROFILESINFO();
                    model = DataRowToModel(dt.Rows[i]);
                    list.Add(model);
                }
            }
           

            return list;
        
        }

		#endregion  Method
	}
}

